﻿// JavaScript Document
function addcomm(article, human){
	var content = $('#CommentContents').val();
	if(!content){
		$('#CommentContents').focus();
		$('#CommentContents').attr('style', 'border:1px solid #e60000;');
		setTimeout("$('#CommentContents').removeAttr('style');", 5000);
		return ;
	}
	if( !human ){
		var visitor = $('#CommentVisitor').val();
		var contact = $('#CommentVisitorContacts').val();
		var datas   = '/&article=' + article + '&visitor=' + visitor + '&contact=' + contact + '&content=' + content;
	} else {
		var datas   = '/&article=' + article + '&human=' + human + '&content=' + content;
	}
	$("#combut").val('已提交');
	$("#combut").attr("disabled", "disabled");
	$.ajax({
		url: '/comments/add', 
		type: 'POST', 
		data: datas,
		dataType: 'json',
		success: function(json){
			if(json.msg){
				$("#combut").val('OK，已提交成功！');
				$("#combut").attr('style', 'color:#FFF;background-color:#7FEA00;border:1px solid #2eEA00;');
				$("#combut").attr("disabled", "disabled");
				setTimeout("$('#combut').val(' 提 交 ');$('#combut').removeAttr('style');$('#combut').removeAttr('disabled');", 60000);
				$('#CommentContents').val('');
			} else {
				alert('提交失败，请稍候再试...');
			}
		},
		error: function (){
			alert('网络错误，请稍候再试...');
		}
	});
}